<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 项目模块
 */
class Project_m extends CI_Model{
	public $tab;
	public $info_tab;
	public function __construct(){
		parent::__construct();
		$this->tab='project';
		$this->info_tab='project_info';
	}
	/**
	 * 添加项目
	 */
	public function add_project_m($a,$is_re_id='0'){
		if(!is_array($a)){
			return false;
		}
		$a['time']=date('Y-m-d H:i:s',time());
		$return=$this->db->insert($this->tab,$a);
		if($is_re_id!='0'){
			return $this->db->insert_id();
		}
		else{
			return $return;
		}
		
	}
	public function update_project($a,$where){
		$a['time']=date('Y-m-d H:i:s',time());
		$query=$this->db->update($this->tab,$a,$where);
		if($query){
			return true;
		}
		else {
			return false;
		}
	}
	public function update_project_info($a,$where){
		$a['time']=date('Y-m-d H:i:s',time());
		$query=$this->db->update($this->info_tab,$a,$where);
		if($query){
			return true;
		}
		else {
			return false;
		}
	}
	/**
	 * 添加项目详细信息
	 */
	public function addProjectInfo($a,$is_re_id='0'){
		if(!is_array($a)){
			return false;
		}
		$a['time']=date('Y-m-d H:i:s',time());
		$return=$this->db->insert($this->info_tab,$a);
		if($is_re_id!='0'){
			return $this->db->insert_id();
		}
		else{
			return $return;
		}
		
	}
	/**
	 * 检查项目名重复
	 *
	 * @param unknown_type $name
	 * @return unknown
	 */
	public function isSameName($name){
		if (isset($name) && !empty($name)) {
			$post['name']=$name;
			$this->db->select('id');
			$query=$this->db->get_where($this->tab,$post);
			$num=$query->num_rows();
			return $num;
		}
		else{
			return false;
		}
		
	}
	/**
	 * 检查项目详细名重复
	 *
	 * @param unknown_type $name
	 * @return unknown
	 */
	public function isSameProInfoName($name,$pid){
		if (isset($name) && !empty($name)) {
			$post['name']=$name;
			$post['pid']=$pid;
			$this->db->select('id');
			$query=$this->db->get_where($this->info_tab,$post);
			$num=$query->num_rows();
			return $num;
		}
		else{
			return false;
		}
		
	}
	/**
	 * 获得项目列表
	 *
	 */
	public function getProjetList($where,$num='0',$offer='0'){
		if($num!='0'){
			$this->db->limit($num,$offer);
		}
		$where['is_del']='1';
		$this->db->order_by('time','desc');
		$query=$this->db->get_where($this->tab,$where);
		$return=$query->result_array();
		return $return;
	}
	/**
	 * 通过pid获得项目详细信息内容
	 *
	 * @param unknown_type $id
	 * @param unknown_type $where
	 * @return unknown
	 */
	public function getProjectInfoByPid($pid,$where=array()){
		if(!empty($pid) && is_numeric($pid)){
			$where['pid']=$pid;
			$query=$this->db->get_where($this->info_tab,$where);
			$return=$query->result_array();
			if($query->num_rows()>0){
				return $return;
			}
			else{
				return  false;
			}
		}
		else{
			return false;
		}
	}
	/**
	 * 通过id获得项目详细信息内容
	 *
	 * @param unknown_type $id
	 * @param unknown_type $where
	 * @return unknown
	 */
	public function getProjectInfoById($where=array()){
		$query=$this->db->get_where($this->info_tab,$where);
		$return=$query->result_array();
		if($query->num_rows()>0){
			return $return;
		}
		else{
			return  false;
		}
	}
	/**
	 * 项目列表数目
	 */
	public function getProjectListNum($where,$limit='')
	{
		if(!empty($limit)){
			$this->db->limit($limit);
		}
		$where['is_del']='1';
		$query=$this->db->get_where($this->tab,$where);
		$return=$query->num_rows();
		return $return;
	}
	/**
	 * 获得项目信息
	 *
	 * @param unknown_type $id
	 * @return unknown
	 */
	public function getProject($id){
		$a['master_ip']='127.0.0.1';
		$a['ip_group']='127.0.0.1,127.0.0.1';
		$a['hostname'] = '127.0.0.1';
		$a['username'] = 'root';
		$a['password'] = '123';
		$a['database'] = 'test';
		$a['dbdriver'] = 'mysql';
		$a['dbprefix'] = '';
		$a['pconnect'] = TRUE;
		$a['db_debug'] = TRUE;
		$a['cache_on'] = FALSE;
		$a['cachedir'] = '';
		$a['char_set'] = 'latin1';
		$a['dbcollat'] = 'latin1_swedish_ci';
		$a['swap_pre'] = '';
		$a['autoinit'] = TRUE;
		$a['stricton'] = FALSE;
		return $a;
		if(!empty($id)){
			$where['id']=$id;
			$this->db->limit('1');
			$query=$this->db->get_where($this->tab,$where);
			if($query->num_rows()>0){
				return $query->row_array();
			}
			else{
				return false;
			}
			
		}
		else{
			return false;
		}
	}
	public function delProject($id){
		if(isset($id) && !empty($id)){
			$where['id']=$id;
			$a['is_del']='0';
			$query=$this->db->update($this->tab,$a,$where);
			return $query;
		}
		else{
			return false;
		}
	}
}